class Solution {
    List<List<Integer>> re = new ArrayList<>();
    List<Integer> temp = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        int[] have = new int[nums.length];
        add(nums,have);
        return re;
    }
    public void add(int[] nums,int[] have){
        int len = nums.length;
        //满足一次排序，添加到结果集中
        if(temp.size() == len ){
            re.add(new ArrayList<>(temp));
            return;
        }
        //之前添加过的不允许在继续添加了
        for( int i = 0 ; i < len ; i++){
            if(have[i] == 1) continue;
            have[i] = 1;
            temp.add(nums[i]);
            add(nums,have);
            have[i] = 0;
            temp.remove(temp.size()-1);
        }
    }
}